﻿/*
 *Copyright (C), 2006-2009, Sunrise Tech. Co., Ltd.
 *SUNRISE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * Created on 2007-11-29
 */
package com.mindao.app.survey.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.mindao.app.common.spring.model.BaseModel;

/**
 * 
 * 功能说明:访谈内容配置
 * 
 * @author liguocai
 */
@Entity
@Table(name = "sv_survey_item_conf")
public class SurveyItemConf extends BaseModel implements Serializable  {
	
	public static final int TYPE_TEXT = 1;//填空
	
	public static final int TYPE_OPTION =2 ;//单选
	
	public static final int TYPE_CHECK =3 ;//多选
	
	public static final int OPTIONAL_TYPE_YES = 1;//必填
	
	public static final int OPTIONAL_TYPE_NO=0 ;//选填	
//	

	// 问题
	private String name;
	
	//显示顺序
	private Integer orderBy;
	
	//类型
	private Integer type;
	
	//可选、必填
	private Integer optionalType;	
	
	private SurveyConf surveyConf;	
	

	private Set<SurveyItemOptionConf> optionConfSet;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(Integer orderBy) {
		this.orderBy = orderBy;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Integer getOptionalType() {
		return optionalType;
	}

	public void setOptionalType(Integer optionalType) {
		this.optionalType = optionalType;
	}
	
	@ManyToOne//(fetch = FetchType.EAGER)  
	@JoinColumn(name = "surveyId")//, nullable = true
	public SurveyConf getSurveyConf() {
		return surveyConf;
	}
	public void setSurveyConf(SurveyConf surveyConf) {
		this.surveyConf = surveyConf;
	}


	
	@OneToMany//(cascade = { CascadeType.ALL  }  )   // ,fetch=FetchType.EAGER去掉懒加载，速度就会变快，如果子记录很多的化
	@JoinColumn(name="itemId")
	public Set<SurveyItemOptionConf> getOptionConfSet() {
		return optionConfSet;
	}

	public void setOptionConfSet(Set<SurveyItemOptionConf> optionConfSet) {
		this.optionConfSet = optionConfSet;
	}
	@Transient
	public String getTypeText() {
		if (this.type==TYPE_TEXT){
			return "问答题";
		}else if (this.type==TYPE_OPTION){
			return "单选";
		}else if (this.type==TYPE_CHECK){
			return "多选";
		}else{
			return "";
		}
	}
	@Transient
	public String getOptionalTypeText() {
		if (this.type==OPTIONAL_TYPE_NO){
			return "选填";
		}else if (this.type==OPTIONAL_TYPE_YES){
			return "必填";
		}else{
			return "";
		}
	}
}
